package com.party.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.party.domain.Reply;
import com.party.domain.User;
import com.party.dto.Response;
import com.party.service.ReplyService;
/**
 * 
 * @author Caizhf
 * @date 2017年5月13日下午10:25:13
 * @version v.0.1
 * @email 1115054416@qq.com 
 *
 * <p>Description: 回复</p>
 *
 */
//后期通过AOP统一处理是否登录
@RestController
@RequestMapping("/reply")
public class ReplyController {
	@Autowired
	private ReplyService replyService;
	
	//访问路径：http://127.0.0.1:8080/party/reply/add?reply_content=贼鸡巴爽&user.id=2&topic.tid=4
	@RequestMapping("/add")
	public Response add(Reply reply){
		User u = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
		reply.setUser(u);
		Reply r = replyService.addReply(reply);
		return Response.success(r);
	}
	
	
	@RequestMapping("/delete/{id}")
	public Response delete(@PathVariable int id){
		replyService.deleteReply(id);
		return Response.success("删除成功");
	}
	
	@RequestMapping("/find/{id}")
	public Response find(@PathVariable int id){
		Reply r = replyService.getByReplyId(id);
		return Response.success(r);
	}
	
}
